﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Collections.Generic;
using Kaesoft.Hospedaje.Entities;

namespace Kaesoft.Hospedaje.Proxy.ServicioClienteReference
{
    public partial class ServicioClienteClient
    {
        public void GrabarLogAsync(string mensaje, string traceEvent, Action<AsyncCompletedEventArgs> method)
        {
            if ((this.onBeginGrabarLogDelegate == null))
            {
                this.onBeginGrabarLogDelegate = new BeginOperationDelegate(this.OnBeginGrabarLog);
            }
            if ((this.onEndGrabarLogDelegate == null))
            {
                this.onEndGrabarLogDelegate = new EndOperationDelegate(this.OnEndGrabarLog);
            }

            System.Threading.SendOrPostCallback customGrabarLogDelegate = new System.Threading.SendOrPostCallback(
            state =>
            {
                if (method != null)
                {
                    InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                    AsyncCompletedEventArgs eventArg = new AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState);
                    if (!WcfProxyInvoker.ExistenErroresAsync(eventArg.Error))
                        Deployment.Current.Dispatcher.BeginInvoke(method, eventArg);
                }
            }
            );

            base.InvokeAsync(this.onBeginGrabarLogDelegate, new object[] {
                        mensaje,
                        traceEvent}, this.onEndGrabarLogDelegate, customGrabarLogDelegate, null);
        }
    }
}